import { request } from '/@/utils/service';

export const GetList = (params: any) => {
    return request({
        url: '/api/sales/performance/',
        method: 'get',
        params
    });
};

export const AddObj = (obj: any) => {
    return request({
        url: '/api/sales/performance/',
        method: 'post',
        data: obj
    });
};

export const UpdateObj = (obj: any) => {
    return request({
        url: '/api/sales/performance/' + obj.id + '/',
        method: 'put',
        data: obj
    });
};

export const DelObj = (id: any) => {
    return request({
        url: '/api/sales/performance/' + id + '/',
        method: 'delete',
        data: { id }
    });
};

export const GetObj = (id: any) => {
    return request({
        url: '/api/sales/performance/' + id + '/',
        method: 'get'
    });
};

export const getSalesPersons = () => {
    return request({
        url: '/api/sales/performance/get_sales_persons/',
        method: 'get'
    });
};

// 新增：计算销售人员在特定周期内的已完成订单总金额
export const calculateActualAmount = (sales_person: string, period: string) => {
    return request({
        url: '/api/sales/performance/calculate_actual_amount/',
        method: 'get',
        params: { sales_person, period }
    });
};

// 新增：更新销售业绩的实际金额
export const updateActualAmount = (id: string) => {
    return request({
        url: `/api/sales/performance/${id}/update-actual-amount/`,
        method: 'put'
    });
}; 